﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nox.Amuse.MVVM;
using System.Reflection;
using Nox.Amuse.Model;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Nox.Amuse.ViewModel.Notification;

namespace Nox.Amuse.ViewModel
{
    class MainWindowViewModel : ObservableObject
    {
        
        public MainWindowViewModel()
        {
            App.Messenger.Register<TabViewModel>(Messages.TabChanged, (tvm) => { UpdateCurrentTab(tvm); });
            App.Messenger.Register(Messages.LineAdded, () => { myTaskBarButton.FlashNotify(); });
        }

        // Models
        private MainWindowSettingsModel WindowSettings = MainWindowSettingsModel.Load();

        // Bound Properties
        /// <summary>
        /// Gets the display title for the window
        /// </summary>
        public string WindowTitle
        {
            get
            {
                if (CurrentTab != null)
                    return CurrentTab.DisplayName + " - " + GetBasicTitle();
                else
                    return GetBasicTitle();
            }
        }

        private string GetBasicTitle()
        {
#if DEBUG
            return Assembly.GetExecutingAssembly().GetName().Version.ToString() + " - Amuse Debug Version";
#else
            return "Amuse - " + Assembly.GetExecutingAssembly().GetName().Version.ToString();
#endif
        }

        public double WindowHeight
        {
            get { return WindowSettings.WindowHeight; }
            set
            {
                WindowSettings.WindowHeight = value;
                base.RaisePropertyChanged("WindowHeight");
            }
        }

        public double WindowWidth
        {
            get { return WindowSettings.WindowWidth; }
            set
            {
                WindowSettings.WindowWidth = value;
                base.RaisePropertyChanged("WindowWidth");
            }
        }

        public double WindowLeft
        {
            get { return WindowSettings.WindowLeft; }
            set
            {
                WindowSettings.WindowLeft = value;
                base.RaisePropertyChanged("WindowLeft");
            }
        }

        public double WindowTop
        {
            get { return WindowSettings.WindowTop; }
            set
            {
                WindowSettings.WindowTop = value;
                base.RaisePropertyChanged("WindowTop");
            }
        }

        public WindowState WindowState
        {
            get { return WindowSettings.WindowState; }
            set
            {
                WindowSettings.WindowState = value;
                base.RaisePropertyChanged("WindowState");
            }
        }

        /// <summary>
        /// Gets or sets the control to display in the Chrome region
        /// </summary>
        public CommandBarViewModel CommandContent
        {
            get { return myCommandContent; }
            set
            {
                myCommandContent = value;
                base.RaisePropertyChanged("CommandContent");
            }
        }
        private CommandBarViewModel myCommandContent = new CommandBarViewModel();

        /// <summary>
        /// Gets or sets the control to display in the Chrome region
        /// </summary>
        public TabBarViewModel TabBarContent
        {
            get { return myTabBarContent; }
            set
            {
                myTabBarContent = value;
                base.RaisePropertyChanged("TabBarContent");
            }
        }
        private TabBarViewModel myTabBarContent = new TabBarViewModel();

        private TabViewModel myCurrentTab;
        public TabViewModel CurrentTab
        {
            get { return myCurrentTab; }
            private set
            {
                myCurrentTab = value;
                base.RaisePropertyChanged("CurrentTab");
                base.RaisePropertyChanged("WindowTitle");
            }
        }

        private TaskBarButton myTaskBarButton = new TaskBarButton();

        private void UpdateCurrentTab(TabViewModel tvm)
        {
            CurrentTab = tvm;
        }

    }
}
